<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ include file="/include/head.jsp"%>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("content") != null ? request.getParameter("content") : "";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/plugins/code/prettify.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/plugins/code/prettify.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/resources/layer/layer.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/resources/layer/extend/layer.ext.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/layer/skin/layer.css"/>
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/layer/skin/layer.ext.css"/>
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/kindeditor/plugins/code/prettify.css" />

<script type="text/javascript">
      var editor;
      KindEditor.ready(function(K) {
			editor = K.create('textarea[name="content"]', {
				uploadJson : '<%=request.getContextPath()%>/back/page/imagePageUpload.do',
				fileManagerJson : '<%=request.getContextPath()%>/back/page/filePageUpload.do',
				allowFileManager : true,
				afterBlur: function() {
				this.sync();
				}
			});
			prettyPrint();
		});
		//添加资讯
		 
		function addNews(){
		  var title=$('#title').val();
          var content=  $('#content').val();
          var author=$('#author').val();
          var intro= $('#intro').val();
           if(title.length==0  || content.length==0||author.length==0||intro.length==0){
		      alert("输入信息不能为空!");
		        return false;
	       } 
	    $.ajax( {
					type : "POST",
					url : "<%=request.getContextPath()%>/back/news/addNewsBean.do",
					data:{"title":title,"author":author,"content":content,"intro":intro},
					dataType: "json",
					async : false,
					success : function(data) {
						if(data.code=="0000"){
				       		 alert("操作成功!");
				       		 layer.open({
					              type: 1,
					              title: false,
					              closeBtn: 2,
					              shadeClose: true,
					              skin: 'layui-layer-nobg',
					              content: "<input style=\"width:100px;height:50px;\" class=\"common_btn jbxx_btn\"  onclick =\"go();\" type=\"button\" value=\"继续添加\">"+
					                       "<input style=\"width:100px;height:50px;\" class=\"common_btn jbxx_btn\"  onclick =\"gotolist();\" type=\"button\" value=\"返回列表\">"
                                    });
				       }else{
				           alert(data.code+data.codeMsg);
				       }
					}
			  }); 
		}
		/**继续添加*/ 
		function go(){
		 location.reload();
		}
		/***返回列表**/
		function gotolist(){
		   window.location.href='<%=request.getContextPath()%>/back/news/getNewsBeans.do';
		}
</script>
  </head>
  
  <body>
   <!-- 遮罩用的div -->
		<div id="divLayer"></div>
		<div class="userr"  >
			<div class="user_borders box_pet"  >
				<div class="r_petmid">
				<form id="submitNews" name="example" method="post" action="" >
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tbody>
								<tr>
									<td width="100" height="70" class="r_name">
									<span class="font_red ml10">*</span>标题：</td>
									<td class="r_namer">
									<input id="title"  name="title" type="text" class="r_form1" value=""  />
									<span id="titleTs" class="fontpink" ></span>
									</td>
								</tr>
								<tr>
									<td width="100" height="70" class="r_name">
									<span class="font_red ml10">*</span>作者：</td>
									<td class="r_namer">
									<input id="author"  name="author" type="text" class="r_form1" value=""/>
									<span id="titleTs" class="fontpink" ></span>
									</td>
								</tr>
									<tr>
									<td height="140" class="r_name t_indent10">简介：</td>
									<td class="r_namer"><label> <textarea
												name="intro"
												onkeyup="this.value=this.value.substring(0,1000)" id="intro"
												cols="100" rows="4" style="resize: none;"></textarea>
									</label></td>
								</tr>
								
								  <tr>
								  <td width="100" height="70" class="r_name">
									<span class="font_red ml10">*</span>内容：</td>
								  <td class="r_namer">
								  <textarea id="content"   name="content" style="width:800px;height:400px;visibility:hidden;" ><%=htmlspecialchars(htmlData)%></textarea>								
								  </td>
								  </tr> 
								<tr>
									<td class="r_namer">
									<input type="button" value="提交" class="new_btn new_btn_submit new_btn_exbig" onclick="addNews()" /> 
									</td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
			</div>
		</div>
  </body>
  
</html>
<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>
